package com.cn.springcloudwechat.controller.pay;

import com.cn.springcloudwechat.common.ajax.AjaxRes;
import com.cn.springcloudwechat.common.utils.base.Const;
import com.cn.springcloudwechat.common.weiXinPay.WeiXinPayConfig;
import com.cn.springcloudwechat.service.pay.PayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

@RestController
@RequestMapping("/weixinPay/")
public class WeChatPayController {
    @Autowired
    private PayService payService;
    @RequestMapping("pay")
    public AjaxRes pay(AjaxRes ajaxRes,HttpServletRequest request, Integer totalFee, String body){
        try {
            Map<Object, Object> objectObjectMap = payService.weChatPay(request, totalFee, body);
            ajaxRes.setSucceed(objectObjectMap, Const.DATA_SUCCEED);
        }catch (Exception e){
            ajaxRes.setFailMsg(e.getMessage());
        }
        return ajaxRes;
        /*HttpSession session = request.getSession();
        String openid = (String) session.getAttribute("openid");
        if(openid!=null){
            //微信公众号进入
            if(UserAgentUtil.isWechat(request)){
                //微信浏览器

            }else{
                System.out.println("错误");
            }
        }else{
            if(!UserAgentUtil.isWechat(request)){
                //h5支付

            }else{
                System.out.println("请在微信外打开浏览器");
            }
        }*/
       /* Map<Object,Object> data= new HashMap<>();
        try {
            HttpSession session = request.getSession();
            String openid = (String) session.getAttribute("openid");
            if(openid==null){
                //
                throw new IllegalArgumentException("openId为空");
            }
            WeiXinPay weiXinPay = new WeiXinPay();
            data = weiXinPay.pay(body,money,null,openid,userId);
            System.out.println("微信支付:"+data);
        }catch (Exception e){
            e.printStackTrace();
        }*/

    }
}
